package com.csvw.skr.basic.service;


import com.webonn.frame.db.MyDao;
import com.csvw.skr.basic.entity.Attachment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/9/24.
 */
@Service
public class AttachmentService {
    @Autowired
    private MyDao myDao;

    public Attachment removeAttachment(Attachment attachment) {
        return myDao.delete(attachment);
    }

    /**
     * 添加上传图片信息
     *
     * @param file
     * @return
     */
    public Attachment saveAttachment(Attachment file) {
        return myDao.persist(file);
    }

    /**
     * 查看某个图片信息
     *
     * @param fileId
     * @return
     */
    public Attachment getAttachment(String fileId) {
        return myDao.get(fileId, Attachment.class);
    }

    /**
     * 查询某个潜客或潜客备注的附件
     *
     * @param owner
     * @return
     */
    public List<Attachment> queryAttachments(String owner) {
        String sql = "select * from ea_pms_contract_attachment where owner = ? ";
        List<Attachment> result = myDao.list(sql, Attachment.class, new Object[]{owner});
        return result;
    }

    /**
     * or ZRG
     */
    public boolean addBatchAttachments(List<Attachment> list_attchments) {
        boolean result = myDao.addBentch(list_attchments);
        return result;
    }

}
